﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WindowsFormsApplication1
{
    class Vector
    {
        double[] vector = new double[4];

        public override Vector operator +(Vector V1, Vector V2)
        {
            Vector x = new Vector(0, 0, 0);
            for (int i = 0; i <= 2; i++)
                x.vector[i] = V1.vector[i] + V2.vector[i];
            return x;
        }

        public override Vector operator -(Vector V1, Vector V2)
        {
            Vector x = new Vector(0, 0, 0);
            for (int i = 0; i <= 2; i++)
                x.vector[i] = V1.vector[i] - V2.vector[i];
            return x;
        }
        
        public override Vector operator *(Vector V1, Vector V2)
        {
            Vector x = new Vector(0,0,0);
            x.vector[0] = V1.vector[1] * V2.vector[2] - V1.vector[2] * V2.vector[1];
            x.vector[1] = V1.vector[0] * V2.vector[2] - V1.vector[2] * V2.vector[0];
            x.vector[2] = V1.vector[0] * V2.vector[1] - V1.vector[1] * V2.vector[0];
            return x;
        }

        public override Vector operator *(double m, Vector V2)
        {
            Vector x = new Vector(0, 0, 0);
            for (int i = 0; i <= 2; i++)
                x.vector[i] = m * V2.vector[i];
            return x;
        }

        static public double dot(Vector V1, Vector V2)
        {
            return V1.vector[0] * V2.vector[0] + V1.vector[1] * V2.vector[1] + V1.vector[2] * V2.vector[2];
        }
        static public double dot(Vector V1)
        {
            return V1.vector[0] * V1.vector[0] + V1.vector[1] * V1.vector[1] + V1.vector[2] * V1.vector[2];
        }

        public Vector unit
        {
            get
            {
                for (int i = 0; i <= 2; i++)
                    unit.vector[i] = this.vector[i] / Math.Sqrt(dot(this));
                return unit;
            }
        }

        public Vector(double x, double y, double z, double t = 0)
        {
            this.vector[0] = x;
            this.vector[1] = y;
            this.vector[2] = z;
            this.vector[3] = t;
        }

        public Vector()
        {
            
        }
    }
}
